package com.cljz.makepassenger.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.cljz.makepassenger.R;
import com.cljz.makepassenger.model.net.bean.ActivityIndexBean;
import com.cljz.makepassenger.ui.holder.HotEventsHolder;

import java.util.List;

/**
 * Created by apple on 2017/4/24.
 */

public class HotEventsAdapter extends RecyclerView.Adapter<HotEventsHolder> {
    private Context context;
    private List<ActivityIndexBean.DataBean.ActivityBean> hotEventsList;
    private OnItemClickListener mOnItemClickListener;


    public HotEventsAdapter(Context context, List<ActivityIndexBean.DataBean.ActivityBean> hotEventsList) {
        this.context = context;
        this.hotEventsList = hotEventsList;
    }


    @Override
    public HotEventsHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new HotEventsHolder(View.inflate(context, R.layout.item_hot_events, null));
    }

    @Override
    public void onBindViewHolder(HotEventsHolder holder, final int position) {
        holder.setData(hotEventsList, position);
        if (mOnItemClickListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    mOnItemClickListener.onClick(hotEventsList.get(position));
                }
            });

            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    mOnItemClickListener.onLongClick(hotEventsList.get(position));
                    return false;
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return hotEventsList == null ? 0 : hotEventsList.size();
    }

    public void setData(List<ActivityIndexBean.DataBean.ActivityBean> hotEventsList) {
        this.hotEventsList = hotEventsList;
        notifyDataSetChanged();
    }

    public interface OnItemClickListener {
        void onClick(ActivityIndexBean.DataBean.ActivityBean dataBean);

        void onLongClick(ActivityIndexBean.DataBean.ActivityBean dataBean);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }
}
